<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const toHex = num => {
      if (num === 0) return '0';
      let res = '';
      const hex = '0123456789abcdef';
      while (num !== 0 && res.length < 8) {
        // num & 0xf将最低的四位取出，对应到16进制上
        res = hex[num & 0xf] + res;
        // 右移4位
        num >>= 4;
      }
      return res;
    };
    console.log(toHex(26))
  </script>
</body>

</html>